package com.inet.consoleservices;


import com.igexin.sdk.PushManager;
import com.inet.baidu.BaiduService;
import com.inet.request.ServerRequest;
import com.inet.util.L;
import com.inet.util.SystemPropertiesProxy;
import com.inet.util.Utils;
import com.inet.util.crashutils.CrashHandler;

import android.app.Application;
import android.content.Intent;

public class MyApplication extends Application {
	public static MyApplication sInstance;
	public static String customId="999";
	public static boolean StartACCON = false;

	public static synchronized MyApplication getInstance() {
		return sInstance;
	}

	@Override
	public void onCreate() {
		super.onCreate();
		sInstance = this;
		// 查询是否是最新版本 返回true则需要更新。。 启动服务则开始下载并安装
		// checkVersion();
		
		// 读取属性文件http.properties
		Utils.readProperties(this);
		
		//获取客户的信息
		try {
			//customId=SystemPropertiesProxy.get(this, "ro.inet.consumer.code", "999");
			customId="999";
		} catch (Exception e) {
			customId="999";
		}
		getCustomSetting();
		
		// 初始化个推SDK
		PushManager.getInstance().initialize(getApplicationContext());
		
		//开启百度服务
		Intent baiduService = new Intent(getApplicationContext(),
				BaiduService.class);
		startService(baiduService);
		
		//开启打印错误log
		CrashHandler.getInstance().init(this);
		
	}
	
	/**
	 * 检查版本号
	 */
	private void checkVersion() {
		new Thread(new Runnable() {
			@Override
			public void run() {
				boolean needUpdate = Utils
						.queryVersion(getApplicationContext());
				if (needUpdate) {
					Intent updateService = new Intent(getApplicationContext(),
							UpdateService.class);
					startService(updateService);
				}
			}
		}).start();
	}
	
	/**
	 * 通过客户编号，从服务器获取相对应的信息
	 */
	private void getCustomSetting() {
		new Thread(new Runnable() {
			
			@Override
			public void run() {
				//这里要传客户编号
				ServerRequest.getCustomInfo(customId);
		}}).start();
	}
}
